//package com.huawo.opensdk.utils;
//
//import android.Manifest;
//import android.annotation.SuppressLint;
//import android.content.Context;
//import android.os.Build;
//import android.util.Pair;
//
//import androidx.fragment.app.FragmentActivity;
//
//import com.huawo.module_interaction.R;
//import com.huawo.module_interaction.scaffold.DialogSupport;
//import com.huawo.module_interaction.ui.page.notification.NotificationUtils;
//import com.huawo.module_service.util.ResourceUtils;
//import com.tbruyelle.rxpermissions2.RxPermissions;
//import com.yullg.android.scaffold.app.Scaffold;
//import com.yullg.android.scaffold.helper.SettingsHelper;
//import com.huawo.module_service.bluetooth.BluetoothSupport;
//import com.yullg.android.scaffold.support.logger.Logger;
//import com.yullg.android.scaffold.support.permission.PermissionSupport;
//import com.yullg.android.scaffold.ui.dialog.AlertDialog;
//
//import java.util.concurrent.atomic.AtomicBoolean;
//
//import io.reactivex.Completable;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import kotlin.Unit;
//
//@SuppressLint("CheckResult")
//public class NewPermissionUtils {
//
//    public static boolean isBluetoothGranted(Context context) {
//        if (Build.VERSION.SDK_INT >= 31) {
//            return PermissionSupport.INSTANCE.checkSelfPermission(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT);
//        }
//        return true;
//    }
//
//    public static Completable requestBluetooth(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= 31) {
//            return requestPermission(activity, R.string.base_permission_request_bluetooth_sdk31, ResourceUtils.getString(R.string.base_permission_request_bluetooth_sdk31_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT);
//        }
//        return Completable.complete();
//    }
//
//    public static Completable requestForWeather(FragmentActivity activity) {
//        return requestPermission(activity, R.string.base_permission_request_function_weather, ResourceUtils.getString(R.string.base_permission_request_function_weather_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION);
//    }
//
//    public static Completable requestForCamera(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_camera, ResourceUtils.getString(R.string.base_permission_request_function_camera_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_camera, ResourceUtils.getString(R.string.base_permission_request_function_camera_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForFeedback(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_feedback, ResourceUtils.getString(R.string.base_permission_request_function_feedback_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_feedback, ResourceUtils.getString(R.string.base_permission_request_function_feedback_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForUserInfoAlbum(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_userinfo_album, ResourceUtils.getString(R.string.base_permission_request_function_userinfo_album_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_userinfo_album, ResourceUtils.getString(R.string.base_permission_request_function_userinfo_album_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForUserInfoCamera(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_userinfo_camera, ResourceUtils.getString(R.string.base_permission_request_function_userinfo_camera_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_userinfo_camera, ResourceUtils.getString(R.string.base_permission_request_function_userinfo_camera_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA);
//        }
//
//    }
//
//    public static Completable requestForBindScan(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= 31) {
//            return requestPermission(activity, R.string.base_permission_request_function_bind_scan_sdk31, ResourceUtils.getString(R.string.base_permission_request_function_bind_scan_sdk31_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA, Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_bind_scan, ResourceUtils.getString(R.string.base_permission_request_function_bind_scan_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION);
//        }
//    }
//
//    public static Completable requestForBindSearch(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= 31) {
//            return requestPermission(activity, R.string.base_permission_request_function_bind_search_sdk31, ResourceUtils.getString(R.string.base_permission_request_function_bind_search_sdk31_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_bind_search, ResourceUtils.getString(R.string.base_permission_request_function_bind_search_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION);
//        }
//    }
//
//    public static Completable requestForWatchface1(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_watchface1, ResourceUtils.getString(R.string.base_permission_request_function_watchface1_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        }else{
//            return requestPermission(activity, R.string.base_permission_request_function_watchface1, ResourceUtils.getString(R.string.base_permission_request_function_watchface1_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForWatchface2(FragmentActivity activity) {
//        return requestPermission(activity, R.string.base_permission_request_function_watchface2, ResourceUtils.getString(R.string.base_permission_request_function_watchface2_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA);
//    }
//
//
//    public static Completable requestForWatchface3(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_watchface3, ResourceUtils.getString(R.string.base_permission_request_function_watchface3_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_watchface3, ResourceUtils.getString(R.string.base_permission_request_function_watchface3_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//    public static Completable requestForWatchface4(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_watchface4, ResourceUtils.getString(R.string.base_permission_request_function_watchface4_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_VIDEO);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_watchface4, ResourceUtils.getString(R.string.base_permission_request_function_watchface4_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForShareWorkouts1(FragmentActivity activity) {
//        return requestPermission(activity, R.string.base_permission_request_function_share1, ResourceUtils.getString(R.string.base_permission_request_function_share1_1, ResourceUtils.getString(R.string.app_name)), Manifest.permission.CAMERA);
//    }
//
//    public static Completable requestForShareWorkouts2(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_share2, ResourceUtils.getString(R.string.base_permission_request_function_share2_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        }else{
//            return requestPermission(activity, R.string.base_permission_request_function_share2, ResourceUtils.getString(R.string.base_permission_request_function_share2_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForShareWorkouts3(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.base_permission_request_function_share3, ResourceUtils.getString(R.string.base_permission_request_function_share2_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_MEDIA_IMAGES);
//        }else{
//            return requestPermission(activity, R.string.base_permission_request_function_share3, ResourceUtils.getString(R.string.base_permission_request_function_share2_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//    public static Completable requestForNotificationCall(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= 26) {
//            return requestPermission(activity, R.string.base_permission_request_function_notification_call, ResourceUtils.getString(R.string.base_permission_request_function_notification_call_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_CONTACTS, Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.SEND_SMS);
//        } else {
//            return requestPermission(activity, R.string.base_permission_request_function_notification_call, ResourceUtils.getString(R.string.base_permission_request_function_notification_call_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_CONTACTS, Manifest.permission.SEND_SMS);
//        }
//    }
//
//    public static Completable requestForNotificationSms(FragmentActivity activity) {
//        return requestSMSPermission(activity, R.string.base_permission_request_function_notification_sms, ResourceUtils.getString(R.string.base_permission_request_function_notification_sms_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.RECEIVE_SMS, Manifest.permission.RECEIVE_MMS, Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS);
//    }
//
//    public static Completable requestForNotificationMissCall(FragmentActivity activity) {
//        return requestPermission(activity, R.string.base_permission_request_function_notification_misscall, ResourceUtils.getString(R.string.base_permission_request_function_notification_misscall_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_CONTACTS);
//    }
//
//    public static Completable requestForContacts(FragmentActivity activity) {
//        return requestPermission(activity, R.string.device_ui_module_contacts_dialog_permission_mgs, ResourceUtils.getString(R.string.base_permission_request_function_notification_misscall_2, ResourceUtils.getString(R.string.app_name)), Manifest.permission.READ_CONTACTS);
//    }
//
//    public static Completable requestForNotificationCalendar(FragmentActivity activity) {
//        return requestPermission(activity, R.string.base_permission_request_function_notification_calendar, (ResourceUtils.getString(R.string.base_permission_request_function_notification_calendar_2, ResourceUtils.getString(R.string.app_name))), Manifest.permission.READ_CALENDAR);
//    }
//
//    private static final AtomicBoolean ONCE_WEATHER = new AtomicBoolean(false);
//
//    public static Completable requestForWeatherOnlyOnce(FragmentActivity activity) {
//        if (NotificationUtils.hasShowOnceNotificationBootDialog() && ONCE_WEATHER.compareAndSet(false, true)) {
//            return requestNativePermissionForWeather(activity);
//        } else {
//            return Completable.complete();
//        }
//    }
//
//    public static Completable requestSMS(FragmentActivity activity) {
//        return Completable.create(emitter -> {
//            try {
//                String[] permissions = new String[]{Manifest.permission.RECEIVE_SMS, Manifest.permission.RECEIVE_MMS, Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS};
//                if (PermissionSupport.INSTANCE.checkSelfPermission(permissions)) {
//                    emitter.onComplete();
//                    return;
//                }
//                new RxPermissions(activity)
//                        .requestEachCombined(permissions)
//                        .subscribe(permission -> {
//                            if (permission.granted) {
//                                emitter.onComplete();
//                            } else {
//                                emitter.onError(new IllegalStateException("Permission denied"));
//                            }
//                        }, error -> {
//                            emitter.onError(error);
//                        });
//            } catch (Exception e) {
//                emitter.onError(e);
//            }
//        }).subscribeOn(AndroidSchedulers.mainThread());
//    }
//
//    public static Completable requestNativePermissionForWeather(FragmentActivity activity) {
//        return Completable.create(emitter -> {
//            try {
//                String[] permissions = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
//                if (PermissionSupport.INSTANCE.checkSelfPermission(permissions)) {
//                    emitter.onComplete();
//                    return;
//                }
//                new RxPermissions(activity)
//                        .requestEachCombined(permissions)
//                        .subscribe(permission -> {
//                            if (permission.granted) {
//                                emitter.onComplete();
//                            } else {
//                                emitter.onError(new IllegalStateException("Permission denied"));
//                            }
//                        }, error -> {
//                            emitter.onError(error);
//                        });
//            } catch (Exception e) {
//                emitter.onError(e);
//            }
//        }).subscribeOn(AndroidSchedulers.mainThread());
//    }
//
//    //额外适配小米十一
//    private static Completable requestSMSPermission(FragmentActivity activity, int message1ResId, String message2ResId, String... permissions) {
//        return Completable.create(emitter -> {
//            try {
//                //更换权限判断方式，新增适配小米十一的权限判断
//                if (NotificationUtils.isSmsPermissionGranted(activity)) {
//                    emitter.onComplete();
//                    return;
//                }
//                DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                        .setCancelable(false)
//                        .setMessageResource(message1ResId)
//                        .setPositiveButtonTextResource(R.string.base_permission_request_dialog_yes, dialog -> {
//                            dialog.dismiss();
//                            new RxPermissions(activity)
//                                    .requestEachCombined(permissions)
//                                    .subscribe(permission -> {
//                                        if (permission.granted) {
//                                            //新增小米权限11短信权限被系统禁止的判断，其他按原先的逻辑走else
//                                            if (!NotificationUtils.isSmsPermissionGranted(activity)) {
//                                                DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                                                        .setCancelable(false)
//                                                        .setMessage(message2ResId)
//                                                        .setPositiveButtonTextResource(R.string.base_permission_request_dialog_settings, i_dialog -> {
//                                                            i_dialog.dismiss();
//                                                            emitter.onError(new IllegalStateException("[4] Permission denied"));
//                                                            SettingsHelper.INSTANCE.startSettingsActivity(
//                                                                    SettingsHelper.INSTANCE.newIntentForApplicationDetailsSettings(Scaffold.getContext().getPackageName()));
//                                                            return Unit.INSTANCE;
//                                                        })
//                                                        .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, i_dialog -> {
//                                                            i_dialog.dismiss();
//                                                            emitter.onError(new IllegalStateException("[3] Permission denied"));
//                                                            return Unit.INSTANCE;
//                                                        })
//                                                        .show();
//                                            } else {
//                                                emitter.onComplete();
//                                            }
//                                        } else if (permission.shouldShowRequestPermissionRationale) {
//                                            emitter.onError(new IllegalStateException("[2] Permission denied"));
//                                        } else {
//                                            DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                                                    .setCancelable(false)
//                                                    .setMessage(message2ResId)
//                                                    .setPositiveButtonTextResource(R.string.base_permission_request_dialog_settings, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[4] Permission denied"));
//                                                        SettingsHelper.INSTANCE.startSettingsActivity(
//                                                                SettingsHelper.INSTANCE.newIntentForApplicationDetailsSettings(Scaffold.getContext().getPackageName()));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[3] Permission denied"));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .show();
//                                        }
//                                    }, error -> {
//                                        emitter.onError(error);
//                                    });
//                            return Unit.INSTANCE;
//                        })
//                        .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, dialog -> {
//                            dialog.dismiss();
//                            emitter.onError(new IllegalStateException("[1] Permission denied"));
//                            return Unit.INSTANCE;
//                        })
//                        .show();
//            } catch (Exception e) {
//                emitter.onError(e);
//            }
//        }).subscribeOn(AndroidSchedulers.mainThread());
//    }
//
//    private static Completable requestPermission(FragmentActivity activity, int message1ResId, String message2ResId, String... permissions) {
//        return Completable.create(emitter -> {
//            try {
//                if (PermissionSupport.INSTANCE.checkSelfPermission(permissions)) {
//                    emitter.onComplete();
//                    return;
//                }
//                DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                        .setCancelable(false)
//                        .setMessageResource(message1ResId)
//                        .setPositiveButtonTextResource(R.string.base_permission_request_dialog_yes, dialog -> {
//                            dialog.dismiss();
//                            new RxPermissions(activity)
//                                    .requestEachCombined(permissions)
//                                    .subscribe(permission -> {
//                                        if (permission.granted) {
//                                            emitter.onComplete();
//                                        } else if (permission.shouldShowRequestPermissionRationale) {
//                                            emitter.onError(new IllegalStateException("[2] Permission denied"));
//                                        } else {
//                                            DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                                                    .setCancelable(false)
//                                                    .setMessage(message2ResId)
//                                                    .setPositiveButtonTextResource(R.string.base_permission_request_dialog_settings, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[4] Permission denied"));
//                                                        SettingsHelper.INSTANCE.startSettingsActivity(
//                                                                SettingsHelper.INSTANCE.newIntentForApplicationDetailsSettings(Scaffold.getContext().getPackageName()));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[3] Permission denied"));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .show();
//                                        }
//                                    }, error -> {
//                                        emitter.onError(error);
//                                    });
//                            return Unit.INSTANCE;
//                        })
//                        .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, dialog -> {
//                            dialog.dismiss();
//                            emitter.onError(new IllegalStateException("[1] Permission denied"));
//                            return Unit.INSTANCE;
//                        })
//                        .show();
//            } catch (Exception e) {
//                emitter.onError(e);
//            }
//        }).subscribeOn(AndroidSchedulers.mainThread());
//    }
//
//    private static Completable requestPermission(FragmentActivity activity, int message1ResId, int message2ResId, String... permissions) {
//        return Completable.create(emitter -> {
//            try {
//                if (PermissionSupport.INSTANCE.checkSelfPermission(permissions)) {
//                    emitter.onComplete();
//                    return;
//                }
//                DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                        .setCancelable(false)
//                        .setMessageResource(message1ResId)
//                        .setPositiveButtonTextResource(R.string.base_permission_request_dialog_yes, dialog -> {
//                            dialog.dismiss();
//                            new RxPermissions(activity)
//                                    .requestEachCombined(permissions)
//                                    .subscribe(permission -> {
//                                        if (permission.granted) {
//                                            emitter.onComplete();
//                                        } else if (permission.shouldShowRequestPermissionRationale) {
//                                            emitter.onError(new IllegalStateException("[2] Permission denied"));
//                                        } else {
//                                            DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                                                    .setCancelable(false)
//                                                    .setMessageResource(message2ResId)
//                                                    .setPositiveButtonTextResource(R.string.base_permission_request_dialog_settings, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[4] Permission denied"));
//                                                        SettingsHelper.INSTANCE.startSettingsActivity(
//                                                                SettingsHelper.INSTANCE.newIntentForApplicationDetailsSettings(Scaffold.getContext().getPackageName()));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, i_dialog -> {
//                                                        i_dialog.dismiss();
//                                                        emitter.onError(new IllegalStateException("[3] Permission denied"));
//                                                        return Unit.INSTANCE;
//                                                    })
//                                                    .show();
//                                        }
//                                    }, error -> {
//                                        emitter.onError(error);
//                                    });
//                            return Unit.INSTANCE;
//                        })
//                        .setNegativeButtonTextResource(R.string.base_permission_request_dialog_no, dialog -> {
//                            dialog.dismiss();
//                            emitter.onError(new IllegalStateException("[1] Permission denied"));
//                            return Unit.INSTANCE;
//                        })
//                        .show();
//            } catch (Exception e) {
//                emitter.onError(e);
//            }
//        }).subscribeOn(AndroidSchedulers.mainThread());
//    }
//
//    // ------------------------------------处理蓝牙服务-------------------------------------------
//
//    public static void requestBluetoothServiceAndRun(FragmentActivity activity, Runnable runnable) {
//        if (BluetoothSupport.INSTANCE.isBluetoothEnabled()) {
//            runnable.run();
//        } else {
//            showBluetoothServiceDisabledDialog(activity);
//        }
//    }
//
//    private static Pair<Integer, AlertDialog> bluetoothServiceActivityAndDialog;
//
//    public static synchronized void showBluetoothServiceDisabledDialog(FragmentActivity activity) {
//        dismissBluetoothServiceDisabledDialog(activity);
//        AlertDialog alertDialog = DialogSupport.alertDialog(activity, DialogSupport.AlertDialogType.NORMAL)
//                .setTitleResource(R.string.base_permission_go_to_bluetooth_settings_title)
//                .setNegativeButtonTextResource(R.string.base_permission_go_to_bluetooth_settings_no, DialogSupport.DEFAULT_ALERT_DIALOG_LISTENER)
//                .setPositiveButtonTextResource(R.string.base_permission_go_to_bluetooth_settings_yes, dialog -> {
//                    dialog.dismiss();
//                    requestBluetooth(activity)
//                            .subscribe(() -> {
//                                BluetoothSupport.INSTANCE.enableBluetooth(activity, 0);
//                            }, error -> {
//                                Logger.Companion.error(null, error);
//                            });
//                    return Unit.INSTANCE;
//                });
//        alertDialog.show();
//        bluetoothServiceActivityAndDialog = new Pair<>(activity.hashCode(), alertDialog);
//    }
//
//    public static synchronized void dismissBluetoothServiceDisabledDialog(FragmentActivity activity) {
//        try {
//            if (bluetoothServiceActivityAndDialog != null && bluetoothServiceActivityAndDialog.first == activity.hashCode()) {
//                bluetoothServiceActivityAndDialog.second.dismiss();
//            }
//            bluetoothServiceActivityAndDialog = null;
//        } catch (Exception e) {
//            Logger.Companion.info(null, e);
//        }
//    }
//    public static Completable requestMusicPermissions(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.add_music_need_perimission, R.string.add_music_need_perimission, Manifest.permission.READ_MEDIA_AUDIO);
//        } else {
//            return requestPermission(activity, R.string.add_music_need_perimission, R.string.add_music_need_perimission, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//
//    public static Completable requestPictureWatchface3(FragmentActivity activity) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            return requestPermission(activity, R.string.device_ui_module_photo_add_permission_hint, R.string.device_ui_module_photo_add_permission_hint, Manifest.permission.READ_MEDIA_IMAGES,Manifest.permission.READ_MEDIA_AUDIO);
//        } else {
//            return requestPermission(activity, R.string.device_ui_module_photo_add_permission_hint, R.string.device_ui_module_photo_add_permission_hint, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
//        }
//    }
//
//}